<template>
	<view class="page_wrap">
		<custom-header :back="false" title="登录" />
		<view class="bg"></view>
		<view class="login_wrap">
			<view class="logo">
				<image src="/static/login/logo.png" mode=""></image>
			</view>
			<view class="text_logo">
				<image src="/static/login/text_logo.png" mode=""></image>
			</view>
			<view class="form_wrap">
				<view class="form_item phone">
					<view class="icon">
						<image src="/static/login/phone_icon.png" mode=""></image>
					</view>
					<view class="input">
						<input type="number" v-model="phone" placeholder="请输入手机号码" />
					</view>
					<view class="right"></view>
				</view>
				<view class="form_item password">
					<view class="icon">
						<image src="/static/login/password_icon.png" mode=""></image>
					</view>
					<view class="input">
						<input type="text" password v-model="password" placeholder="请输入密码" />
					</view>
				</view>
				<view class="btn_wrap">
					<button
						size="default" 
						type="default" 
						class="btn"
						hover-class="confirm_hover"
						:hover-stay-time="200"
						:loading="loading"
						@click="handleLogin">立即登录</button>
				</view>
			</view>
		</view>
	</view>
	<!-- 弹出层提示 -->
	<custom-toast 
		:show="isShowToast"
		:config="toastConfig"
		@cancel="hideToast"
		@confirm="confirmToast" />
</template>

<script setup>
	import { ref,computed,onUnmounted } from 'vue'
	import { isvalidPhoneNumber } from '../../utils/validate.js'
	
	// 弹出层操作
	import useToast from '../../utils/toast.js'
	const { isShowToast,toastConfig,showToast,hideToast } = useToast()
	// 弹出层确认
	const confirmToast = ()=>{
		hideToast()
	}
	
	const phone = ref('')
	const password = ref('')
	const loading = ref(false)
	
	const handleLogin = ()=>{
		if(!phone.value){
			showToast('请输入手机号码')
			return
		}
		if(!isvalidPhoneNumber(phone.value)){
			showToast('手机号码格式不正确')
			return
		}
		if(!password.value){
			showToast('请输入密码')
			return
		}
		loading.value = true
		setTimeout(()=>{
			loading.value = false
			uni.reLaunch({
				url:'/pages/index/index'
			})
		},800)
	}
</script>

<style lang="scss">
	.page_wrap{
		min-height: 100vh;
		background: #fff;
	}
	.bg{
		width: 100%;
		height: 253rpx;
		background: url('https://goods-1312936761.cos.ap-chongqing.myqcloud.com/applet/supplier/login/bg.png');
		background-size: cover;
		position: relative;
		z-index: 1;
	}
	.login_wrap{
		transform: translateY(-150rpx);
	}
	.logo{
		width: 180rpx;
		height: 120rpx;
		margin: 0 auto;
	}
	.text_logo{
		width: 325rpx;
		height: 80rpx;
		margin:60rpx auto 0;
	}
	.form_wrap{
		padding:30rpx 75rpx 0;
		.form_item{
			height: 88rpx;
			border-radius: 99rpx;
			background: #F8F8F8;
			display: flex;
			align-items: center;
			justify-content: space-between;
			font-size: 28rpx;
			padding:0 25rpx;
			margin-top: 40rpx;
			.icon{
				width: 28rpx;
				height: 28rpx;
				display: flex;
			}
			.input{
				flex: 1;
				padding-left: 20rpx;
				input{
					width: 100%;
				}
			}
			.right{
				width: 200rpx;
				color: #F5564D;
				text-align: center;
			}
		}
	}
	.btn_wrap{
		margin-top: 50rpx;
		.btn{
			// width: 100%;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			border-radius: 99rpx;
			background:  #F5564D !important;
			color: #fff !important;;
			font-size: 32rpx !important;;
			font-weight: bold;
		}
	}
	.register{
		padding-top: 30rpx;
		display: flex;
		justify-content: flex-end;
		color: #F5564D;
		font-size: 28rpx;
	}
	.read{
		display: flex;
		justify-content: center;
		align-items: center;
		width: 100%;
		position: fixed;
		bottom: 120rpx;
		left: 0;
		.icon{
			width: 24rpx;
			height: 24rpx;
			display: flex;
		}
		.text{
			font-size: 24rpx;
			color: #bbb;
			padding-left: 10rpx;
			text{
				color: #F5564D;
			}
		}
	}
	
</style>
